package com.bing.java.collection.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * List遍历方式
 * 
 * @author bing
 *
 *         2019年11月9日 下午5:05:28
 */
public class ListIterator {

	public static void main(String[] args) {

		List<String> list = new ArrayList<>();
		list.add("Java 1.5");
		list.add("Java 1.6");
		list.add("Java 1.7");

		System.out.println(">>>> for loop:");
		for (int i = 0; i < list.size(); i++) {
			System.out.println("list.get(i) = " + list.get(i));
		}

		System.out.println(">>>> for loop enhanced:");
		for (String ele : list) {
			System.out.println("ele = " + ele);
		}

		System.out.println(">>>> iterator:");
		Iterator<String> iterator = list.iterator();
		while (iterator.hasNext()) {
			System.out.println("iterator.next() = " + iterator.next());
		}

		/**
		 * 在Java8中的遍历方式
		 */
		System.out.println("\nJAVA8:::Collection.forEach ======================>");
		list.forEach(System.out::println);

		System.out.println("\nJAVA8:::Collection.stream.map ==================>");
		list.stream().map(item -> "Mapped_Value_" + item).collect(Collectors.toList()).stream().forEach(System.out::println);
		
		System.out.println("\nJAVA8:::Collection.stream.filter.map ==========>");
		list.stream().filter(item -> item.contains("Java")).map(item -> "Mapped_Value_" + item).collect(Collectors.toList()).stream()
				.forEach(System.out::println);
	}

}
